#ifndef SYSTEMTRAYMANAGER_H
#define SYSTEMTRAYMANAGER_H

#include <QObject>
#include <QSystemTrayIcon>
#include <QAction>
#include <QMenu>
#include <QIcon>

class SystemTrayManager : public QObject
{
    Q_OBJECT
    Q_PROPERTY(bool trayVisible READ trayVisible WRITE setTrayVisible NOTIFY trayVisibleChanged)

public:
    explicit SystemTrayManager(QObject *parent = nullptr);
    ~SystemTrayManager();

    bool trayVisible() const { return m_trayIcon && m_trayIcon->isVisible(); }
    void setTrayVisible(bool visible);

    Q_INVOKABLE void showTrayIcon();
    Q_INVOKABLE void hideTrayIcon();
    Q_INVOKABLE void setTrayToolTip(const QString &tooltip);

signals:
    void trayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void trayVisibleChanged(bool visible);
    void showWindowRequested();
    void quitRequested();

private slots:
    void onTrayIconActivated(QSystemTrayIcon::ActivationReason reason);
    void onQuitActionTriggered();

private:
    void createTrayIcon();
    void createTrayMenu();

    QSystemTrayIcon *m_trayIcon;
    QMenu *m_trayMenu;
    QAction *m_quitAction;
    QIcon m_defaultIcon;
};

#endif // SYSTEMTRAYMANAGER_H

